import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: D1
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/10 10:41
 */
public class D1 {
    public static void main(String[] args) {
        LocalDate ld = LocalDate.now();
        System.out.println(ld);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            var d = sdf.parse("2000-07-23");
            System.out.printf("%tF", d);
            System.out.println();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        LocalDateTime ldt = LocalDateTime.now();
        System.out.printf("%tF %<tT", ldt);
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        dtf.localizedBy(Locale.US);
        var t = dtf.parse("2001年07月23日");
        System.out.println();
        System.out.printf("%n%tF", t);
        LocalDate l = LocalDate.of(2022, 1, 1);
        System.out.println();
        System.out.println(l.isLeapYear());
        System.out.println(l.getYear());
        System.out.println(l.getMonth());
        System.out.println(l.getMonthValue());
        System.out.println(l.getDayOfMonth());
        System.out.println(l.getDayOfWeek());
        System.out.println(l.getDayOfYear());
        LocalDateTime ll = LocalDateTime.now();
        //ll.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"));
        //LocalDateTime转换成Date
        Date date = new Date(ll.toInstant(ZoneOffset.of("+8")).toEpochMilli());
        System.out.println("-------------------");
        System.out.println(date.getTime());
        System.out.println(System.currentTimeMillis());
        System.out.printf("%tF %<tT%n", ll);
        //LocalDate传入参数及格式
        LocalDate l1 = LocalDate.parse("1999-08-02", DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.CHINA));
        System.out.println(l1.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日", Locale.CHINA)));
        System.out.println(l1.getMonth());
        System.out.println();

    }
}
